package cn.zhf.shop.controller;

import cn.zhf.shop.entity.CreditApply;
import cn.zhf.shop.entity.Message;
import cn.zhf.shop.entity.search.ConsoleUserSearch;
import cn.zhf.shop.entity.search.CreditApplySearch;
import cn.zhf.shop.service.CreditApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "信用卡申请模块")
@RequestMapping("/api/creditApply")
public class CreditApplyController {

    @Resource
    private CreditApplyService creditApplyService;


    @PostMapping("/")
    @ApiOperation(value = "新增信用卡申请记录")
    public Message<?> insert(CreditApply c){

        return creditApplyService.insert(c);
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取所有申请记录")
    public Message<List<CreditApply>> getAll(){
        return creditApplyService.getAll();
    }

    @GetMapping("/id")
    @ApiOperation(value = "根据申请编号获取申请记录")
    public Message<CreditApply> getCreditApplyById(Integer id){
        return creditApplyService.getById(id);
    }

    @PostMapping("/id")
    @ApiOperation(value = "根据id修改申请状态")
    public Message<?> updateStatusById(Integer id,Integer status){
        return creditApplyService.updateStatusById(id,status);
    }

    @GetMapping("/phone/all")
    @ApiOperation(value = "根据phone获得所有的申请记录")
    public Message<List<CreditApply>> getAllByUserId(String phone){
        return creditApplyService.selectByPhone(phone);
    }

    @ApiOperation("模糊搜索")
    @PostMapping("/mohu/search")
    public Message<List<CreditApply>> mohusearch(String str){
        return creditApplyService.selectByIdAndBankNameAndUserNameAndPhoneAndResultAndUserIdcard(str);
    }

    @ApiOperation("条件搜索")
    @PostMapping("/confident/search")
    public Message<List<CreditApply>> confidentsearch(Integer id, String bankName, String userName, String phone, Integer result, String userIdcard){
        return creditApplyService.selectByIdAndBankNameAndUserNameAndPhoneAndResultAndUserIdcard2(id, bankName, userName, phone, result, userIdcard);
    }

    @ApiOperation(value = "多条件组合模糊查询")
    @PostMapping("/mohu/condition/search")
    public Message mohuConditionSearch(CreditApplySearch c){

        return creditApplyService.mohuConditionSearch(c);
    }

}
